package com.bwf.set;

import java.util.Objects;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/23 14:10
 * @Copyright 博为峰
 */
public class Student implements Comparable {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        System.out.println("----------------equals-------------------");
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        System.out.println("----------------hashcode-------------------");
        return Objects.hash(name, age);
    }

    @Override //排序，唯一（不可重复）
    public int compareTo(Object o) {//Object o = new Student("张三",20)
        Student student = (Student) o;
        System.out.println("student:" + student);
        System.out.println("this:" + this);
        System.out.println("----------------compareTo-------------------");
//        return this.name.compareTo(student.name);
        return student.age - this.age;
    }
}
